from unittest import TestCase
from ddt  import ddt,data,unpack
from selenium import webdriver
from Online_loanOperation import Online_loanOperation
from Online_loan_data import Online_loan_data

@ddt
class Test5Online_loan(TestCase):
#########################################################################################
###################################      贷款申请      ###################################

    @data(*Online_loan_data.Online_loan_application_data)
    @unpack
    def testOnline_loan1(self,username,password,payment_password,loan_amount,loan_term,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        ol = Online_loanOperation()
        ol.Online_loan_before(driver,username,password)
        num1 = ol.loannum(driver)
        ol.Online_loan_apply(driver,loan_amount,loan_term)
        num2 = ol.loannum(driver)
        result = ol.getapplyResult(num1,num2)

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)

#########################################################################################
###################################      贷款审批      ###################################

    @data(*Online_loan_data.Online_loan_review_data)
    @unpack
    def testOnline_loan2(self,username,password,payment_password,loan_amount,loan_term,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        ol = Online_loanOperation()
        ol.Online_loan_before(driver,username,password)
        num1 = ol.money(driver)
        num1 = num1 + float(loan_amount)
        ol.Online_loan_apply(driver,loan_amount,loan_term)
        ol.Loan_review()
        num2 = ol.money(driver)
        result = ol.getreviewResult(num1,num2)

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)